package homework;

import java.time.Year;
import java.util.*;

public class FightLandlords extends Card {

    private ArrayList<Card> poker = new ArrayList();

    private String[] pointArr = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
    private String[] typeArr = {"♥", "♠", "♣", "♦"};
    private int[] valueArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

    public static void main(String[] args) {
        FightLandlords dok = new FightLandlords();
        dok.init();
        dok.shuffleCard();
        dok.deal();
    }

    //初始化54张牌
    public void init() {
        for (int i = 0; i < pointArr.length; i++) {
            for (int j = 0; j < typeArr.length; j++) {
                poker.add(new Card(pointArr[i], typeArr[j], valueArr[i]));
            }
        }
        poker.add(new Card("小王", "", 14));
        poker.add(new Card("大王", "", 15));

        System.out.println(poker);
    }

    //洗牌
    public void shuffleCard() {
        Collections.shuffle(poker);
        System.out.println(poker);
    }

    //发牌并排序
    public void deal() {
        List one = poker.subList(0, 17);
        one.sort(new Comparator<Card>() {
            @Override
            public int compare(Card c1, Card c2) {
                return c1.getValue() - c2.getValue();
            }
        });
        System.out.println(one);
        List two = poker.subList(17, 34);
        two.sort(new Comparator<Card>() {
            @Override
            public int compare(Card c1, Card c2) {
                return c1.getValue() - c2.getValue();
            }
        });
        System.out.println(two);

        List three = poker.subList(34, 51);
        three.sort(new Comparator<Card>() {
            @Override
            public int compare(Card c1, Card c2) {
                return c1.getValue() - c2.getValue();
            }
        });
        System.out.println(three);

        List bottom = poker.subList(51, 54);
        System.out.println(bottom);
    }

}
